package com.kobe.tokendemo.controller;

import com.kobe.tokendemo.ResultWrapper;
import com.kobe.tokendemo.entity.User;
import com.kobe.tokendemo.utils.JWTUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 创建 JYQ  on  2018/11/1,15:32
 */
@RestController
public class LoginController {
   @PostMapping("/login")
    public ResultWrapper login(User user){
        Map<String, Object> map = new HashMap<>();

        if(user.getUserName().equals("admin")&& user.getPassword().equals("admin")){
            map.put("Authentication", JWTUtils.newToken(1l,6000L));
            return  ResultWrapper.success(map);
        }
        return ResultWrapper.error(401,"cuowu");

    }
    @GetMapping("/index")
    public  String index(){
      return  "redirect:http://baidu.com";
    }





}
